package com.sunny;

import java.util.concurrent.LinkedBlockingQueue;

public class BuildTest {

    public TreeNode build(int[] arr){
        if(arr.length == 0)
            return null;
        TreeNode root = new TreeNode(arr[0]);
        for(int i=1;i<arr.length;i++){
            buildCore(root, arr, i);
        }
        return root;
    }

    public void buildCore(TreeNode root,int[] arr, int ind){
        TreeNode cur = root;
        while (true){
            if(cur.value > arr[ind]){
                if(null != cur.left){
                    cur = cur.left;
                }else{
                    TreeNode tmp = new TreeNode(arr[ind]);
                    cur.left = tmp;
                    break;
                }
            }else if(cur.value < arr[ind]){
                if(null != cur.right){
                    cur = cur.right;
                }else{
                    TreeNode tmp = new TreeNode(arr[ind]);
                    cur.right = tmp;
                    break;
                }
            }else{
                break;
            }
        }
    }

    public static void main(String[] args) {

        BuildTest buildTest = new BuildTest();

        int[] arr = {1,3,7,5,8,2,9,3};
        TreeNode root = buildTest.build(arr);


        System.out.println(root);
    }

}
